<?php
    $content    = 'company/product.php';
    $post_title     = '';
    require_once TMP_SELL_PATH;
$cat_id = isset($_GET['incategory'])?$_GET['incategory']:'';

if($cat_id!=''){
	$sql2 = "AND pic.category_id IN ($cat_id) ";	
}else{
	$sql2 = '';	
}

// price between
$priceFrom = isset($_GET['pfrom'])?$_GET['pfrom']:'';
$priceTo = isset($_GET['pto'])?$_GET['pto']:'';
if($priceFrom!='' and $priceTo!='')
    {
        $s_price = 'AND ph.`price` BETWEEN '.$priceFrom.' AND '.$priceTo.'';
    }
    else
    {
        if($priceFrom!='')
        {
            $s_price = 'AND ph.`price` >= '.$priceFrom.'';
        }
        else if($priceTo!='')
        {
            $s_price = 'AND ph.`price` <= '.$priceTo.'';
        }
        else
        {
            $s_price = '';
        }        
    }
// price between

// search in seller
if(isset($cat_id_get['id']))
    {
        $seller_Id = "AND p.`owner`='".$cat_id_get['id']."'";
    }
    else
    {
        $seller_Id = '';
    }
// end search in seller


$pro_name = isset($_GET['txtsearch'])?$_GET['txtsearch']:'';
    $pro_name = preg_replace("/[^a-zA-Z0-9]+/", "", html_entity_decode($pro_name, ENT_QUOTES));


?>
		<div class="twelve columns">
            <div class="bo_eee radius1 ba_fff pad_10" style="margin-right: 15px; margin-bottom:15px;">
                <h4>Search Result for Keyword &quot;<?php echo $pro_name;?>&quot;</h4>
            </div>        
        </div>
<?php
    $sql = "SELECT distinct ph.product_id, ph.country_id, p.*, ph.*, pic.* FROM tblproduct AS p, tblproduct_in_pharmacy AS ph, tblproduct_in_category AS pic  WHERE p.product_name LIKE '$pro_name%' $sql2 AND p.status = 1 AND ph.status = 1 AND ph.product_id = p.id $s_price $seller_Id GROUP BY ph.product_id ORDER BY p.product_name";
    		$result = mysql_query($sql);
    		if(dbNumRows($result)){
    		$i = 1;
    			while($row = mysql_fetch_assoc($result)){
    				$sql_img = "SELECT thumbnail FROM tblimage WHERE product_id = ".$row['id']." LIMIT 0,1";
    				$result_img = mysql_query($sql_img);
    				$row_img = mysql_fetch_assoc($result_img);
    				$i++;
    				$pharmacy=mysql_query("SELECT COUNT(DISTINCT pharmacy_id) AS pid
    				FROM tblproduct_in_pharmacy WHERE product_id=".$row['id']."");
    				
    				$price=mysql_query("SELECT price FROM tblproduct_in_pharmacy WHERE product_id=".$row['id']." ORDER BY price ASC LIMIT 0,1");
    				$myprice=mysql_fetch_assoc($price);
    				$price1=mysql_query("SELECT price FROM tblproduct_in_pharmacy WHERE product_id=".$row['id']." ORDER BY price DESC LIMIT 0,1");
    				$myprice1=mysql_fetch_assoc($price1);				
		?>
     <div class="three columns">
    	<div class="product-cat">        
        <?php
		if($row_img['thumbnail']!=""){
			$thumbnail_i = 	$row_img['thumbnail'];
		}else{
			$thumbnail_i = 	'no-image-small.png';
		}
		?>
                   <div class="image_por">
                        <a href="product/product_detail.php?product_id=<?php echo $row['id']?>" title="<?php echo $row['product_name']; ?>"><img src="<?php echo W_S_IMAGES_DIR.$thumbnail_i; ?>" /></a>
                   </div>
                    <div class="pro-title">
                    <a href="product/product_detail.php?product_id=<?php echo $row['id']?>" title="<?php echo $row['product_name']; ?>"><?php echo $row['product_name']; ?></a>
                    </div>
                    <div class="add-tocart">
                        <a class="btn btn-mini btn-success" href="libraryfiles/cart-functions.php?action=add&amp;pid=<?php echo $row['id']?>">add to cart</a>
                    </div>
                    <div class="row">                   		
                    <span class="price">
                    <?php 
                                        if($myprice['price']==$myprice1['price']){
                                            echo $myprice['price']."$";
                                        }
                                        else{
                                            echo $myprice['price'] .' - '. $myprice1['price']."$" ; 
                                        }
                    ?>
                     </span>                   	 

                    </div>                 
         </div>         
     </div>         
     
    

            <?php
			}
		}else{
		?>

    <h3 align="center">No Product Found!</h3>
       
        <?php	
		}
		?>   
    
